USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpTractorPurchaseByInvoiceId]    Script Date: 05/25/2014 16:43:32 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SpTractorPurchaseByInvoiceId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SpTractorPurchaseByInvoiceId]
GO

USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpTractorPurchaseByInvoiceId]    Script Date: 05/25/2014 16:43:32 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROC [dbo].[SpTractorPurchaseByInvoiceId]
(@INVOICE_ID INT)
AS
BEGIN
SELECT 
        TRACTOR_MODEL_NAME
        ,TRACTOR_ENGINE_NO
        ,TRACTOR_SPECIFICATION
        ,VAT_PERCENTAGE
        ,INVOICE_DISCOUNT
        ,[TRACTOR_PURCHASE_RATE] AS INVOICE_GRANDTOTAL
         ,TP.INVOICE_ID
         ,replace(convert(NVARCHAR, INVOICE_DATE, 106), ' ', '-')AS INVOICE_DATE 
         ,INVOICE_NO
         ,TRACTOR_CHASSIS_NO
	 
          
 FROM TRACTOR_PURCHASES TP
  LEFT OUTER JOIN INVOICE I ON I.INVOICE_ID=TP.INVOICE_ID
  LEFT OUTER JOIN TRACTOR_MODELS TM ON TM.TRACTOR_MODEL_ID=TP.TRACTOR_MODEL_ID
            
 WHERE TP.INVOICE_ID=@INVOICE_ID 
     
END



GO


